package com.lanhu.designpattern.singleton.lazy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * author:zhangzg
 * date:2020/11/1 0:12
 */
public class Test {
    public static void main(String[] args) {
//        Thread thread = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                SingletonDoubleCheckLazy singletonDoubleCheckLazy = SingletonDoubleCheckLazy.getInstance();
//            }
//        });
//        Thread thread2 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                SingletonDoubleCheckLazy singletonDoubleCheckLazy = SingletonDoubleCheckLazy.getInstance();
//            }
//        });
//        thread2.start();
//        thread.start();

        Class<SingletonInnerClass> clzz = SingletonInnerClass.class;
        try {
            Constructor<SingletonInnerClass> declaredConstructor = clzz.getDeclaredConstructor(null);
            declaredConstructor.setAccessible(true);
            SingletonInnerClass singletonInnerClass1 = declaredConstructor.newInstance();
            SingletonInnerClass singletonInnerClass2 = SingletonInnerClass.getInstance();
            System.out.println(singletonInnerClass1.hashCode());
            System.out.println(singletonInnerClass2.hashCode());
            System.out.println(singletonInnerClass1 == singletonInnerClass2);



        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }


    }
}
